package com.cxg.fairy.ec.main.personal.coupon;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.SimpleClickListener;
import com.cxg.fairy.ec.main.order.PostOrderDelegate;
import com.cxg.fairy.ui.recycler.MultipleItemEntity;
import com.cxg.fairy.util.log.LatteLogger;
import com.cxg.fairy.util.storage.LattePreference;
import com.cxg.fairy.util.toasty.Toasty;

import java.util.WeakHashMap;

/**
 * Created by Administrator on 2018/4/18.
 */

public class CouponListClickListener extends SimpleClickListener {

    private final CouponTabDelegate DELEGATE;

    private final PostOrderDelegate PDELEGATE;

    public CouponListClickListener(CouponTabDelegate delegate,PostOrderDelegate postOrderDelegate) {
        this.DELEGATE = delegate;
        this.PDELEGATE = postOrderDelegate;
    }

    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        MultipleItemEntity entity = (MultipleItemEntity) baseQuickAdapter.getData().get(position);
        WeakHashMap argsMap = new WeakHashMap();
        String couponStatus = entity.getField(CouponItemFields.COUPON_STATUS);
        LatteLogger.e("couponStatus=",couponStatus);
        if ("use1".equalsIgnoreCase(couponStatus)) {
            argsMap.put("POST_ORDER_COUPON_NO", String.valueOf(entity.getField(CouponItemFields.COUPON_NO)));
            LattePreference.addCustomAppProfile("POST_ORDER_COUPON_NO", String.valueOf(entity.getField(CouponItemFields.COUPON_NO)));
            PDELEGATE.getSupportDelegate().pop();
            DELEGATE.getSupportDelegate().pop();
            DELEGATE.getSupportDelegate().start(PostOrderDelegate.create(argsMap));
        } else {
            Toasty.warning(DELEGATE.getContext(), "该优惠券不可用!").show();
        }
    }

    @Override
    public void onItemLongClick(BaseQuickAdapter adapter, View view, int position) {

    }

    @Override
    public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {

    }

    @Override
    public void onItemChildLongClick(BaseQuickAdapter adapter, View view, int position) {

    }
}
